package com.webchat.pgc.repository.dao.mall;

import com.webchat.domain.inter.mall.MallShopReviewInter;
import com.webchat.pgc.repository.entity.mall.MallShopReview;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface IMallShopReviewDAO extends JpaRepository<MallShopReview, Long> {

    @Query(nativeQuery = true,
           value = "select sr.id, s.id as shopId, " +
                    "sr.review_status as reviewStatus, sr.review_reason as reviewReason, " +
                    "sr.create_by as createUserId, sr.update_by as updateUserId," +
                    "sr.create_date as submitDate, sr.update_date as reviewDate " +
                    "from web_chat_mall_shop_review sr " +
                    "inner join web_chat_mall_shop s " +
                    "on sr.shop_id = s.id " +
                    "where 1=1 " +
                    "and if(:shopName is not null and :shopName != '', s.name like concat('%', :shopName, '%'), 1) " +
                    "and if(:reviewStatus is not null and :reviewStatus != '', sr.review_status = :reviewStatus, 1) ",
           countQuery = "select count(1) " +
                   "from web_chat_mall_shop_review sr " +
                   "inner join web_chat_mall_shop s " +
                   "on sr.shop_id = s.id " +
                   "where 1=1 " +
                   "and if(:shopName is not null and :shopName != '', s.name like concat('%', :shopName, '%'), 1) " +
                   "and if(:reviewStatus is not null and :reviewStatus != '', sr.review_status = :reviewStatus, 1) ")

    Page<MallShopReviewInter> page(String shopName, Integer reviewStatus, Pageable pageable);
}
